﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using abp.Roles;
using Volo.Abp.Domain.Entities.Auditing;

namespace abp.Users
{
    public class LoginUser: AuditedAggregateRoot<Guid>
    {
        protected LoginUser()
        {
        }

        public LoginUser(string userName,string displayName,string password)
        {
            UserName = userName;
            displayName = DisplayName;
            Password = password;
        }
        

        /// <summary>
        /// 用户名
        /// </summary>
        [Required]
        [MaxLength(25)]
        public string UserName { get; set; }

        /// <summary>
        /// 显示名
        /// </summary>
        [MaxLength(50)]
        public string DisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(DisplayName)) return UserName;
                return DisplayName;
            }
        }

        /// <summary>
        /// 密码
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Password { get; set; }

        /// <summary>
        /// 是否启动
        /// </summary>
        public bool IsEnable { get; set; }


        private  List<LoginRole> roles;

        /// <summary>
        /// 所包含的角色
        /// </summary>
        public IReadOnlyList<LoginRole> Roles => this.roles?.AsReadOnly();

        /// <summary>
        /// 添加角色
        /// </summary>
        public virtual void AddRole(LoginRole role)
        {
            //todo 用户添加角色的时候增加校验

            (roles??new List<LoginRole>()).Add(role);
        }

        public virtual void SetEnable()
        {
            this.IsEnable = true;
        }


    }
}
